﻿$(function () {
    $("#stuFinance-grid").datagrid({
        url: $.Api("Dri/StuFinance/Grid"),
        nowrap: false, rownumbers: true, border: false,
        fit: true, singleSelect: true,
        pageSize: 20, pagination: true,
        idField: "ID", toolbar: "#stuFinance-tools",
        remoteSort: false,
        columns:
        [[
            { field: "StudentInfo", title: "学员信息", width: 180, align: "center", sortable: true },
            { field: "CostType", title: "费用类型", width: 150, align: "center", sortable: true },
            { field: "Cost", title: "费用", width: 100, align: "center", sortable: true },
            { field: "Description", title: "描述", width: 300, align: "center", sortable: true },
            { field: "InsertTime", title: "创建时间", width: 150, align: "center", sortable: true }
        ]],
        //合并单元格
        onLoadSuccess: function (data) {
            if (data.rows.length > 1) {
                //var tTable = $("#myDataGrid");
                //mergeCellsGroupByField(tTable, "UserName,RealName,Email,Contactphone,Description,AddDate", 0, data.rows.length);
                //以上合并方法是不是有问题呢？先只合并学员信息
                $.MergeCellsByField("stuFinance-grid", "StudentInfo");
            }
        },
        onDblClickRow: function (index, row) {
            StuFinance.Update();
        }
    });
});

var StuFinance = {
    ////添加
    //Insert: function () {
    //    StuFinance.Mutual("添加", "dri/stuFinance/Edit.aspx");
    //},
    //修改
    Update: function () {
        var row = $("#stuFinance-grid").datagrid("getSelected");
        if (row) {
            StuFinance.Mutual("修改", "dri/stuFinance/Edit.aspx?id=" + row.ID);
        }
        else { $.EasyuiSlide(nullrowmsg); }
    },
    //删除
    Delete: function () {
        var row = $("#stuFinance-grid").datagrid("getSelected");
        if (row) {
            $.EasyuiConfirm("确认删除?", function (del) {
                if (del) {
                    $.AjaxMask({
                        url: $.Api("Dri/StuFinance/Delete"),
                        type: "post", data: { id: row.ID },
                        success: function (result) {
                            result = JSON.parse(result);
                            $.EasyuiSlide(result.Message);
                            if (result.Success) { StuFinance.Reload(); }
                        }
                    });
                }
            });
        }
        else { $.EasyuiSlide(delnullrowmsg); }
    },
    //实体操作
    Mutual: function (title, href) {
        $.ModelDialog({
            title: title, href: href, width: 260,
            handler: function () {
                $.ModelForm({
                    validate: true, button: $(this),
                    id: "#stuFinance-model",
                    url: $.Api("Dri/StuFinance/Save"),
                    success: function (result) { StuFinance.Reload(); }
                });
            },
            onLoad: function () { StuFinance.FormInit(); }
        });
    },
    //弹窗初始化
    FormInit: function () {
        $("#cost-type").combobox({
            width: 150, panelHeight: "auto",
            url: $.Api("Sys/Dictionary/List&tag=CostType"),
            valueField: 'text',
            textField: 'text'
        });
    },

    //刷新列表
    Reload: function () {
        $.DataGridReload("#stuFinance-grid");
    },

    //导出表格
    Export: function () {
        location.href = $.Api("Dri/StuFinance/Export"); return false;
    }
};